#!/bin/bash

HIVE_PA="/home/hadoop/hive/hive-0.10.0"
PassWd="pass@word1"

#name="select SSTZ, stddev($2),avg($2),min($2),max($2) from XJFDDY group by SSTZ;"
sql_n="select b.SSTZ AS temps,(stddev(b.temps)) AS STD,avg(b.temps) AS AVG,min(b.temps) AS MIN,max(b.temps) AS MAX from XJFDDY b group by b.SSTZ;"
sql_s="select SSTZ, temps from xjfddy group by sstz,temps;"

#Numberarray
Numberarray[0]="yxtchd"
#Numberarray[1]="yzhcd"
#Numberarray[2]="tryjzhl"
#Numberarray[3]="trsjd"
#Numberarray[4]="zacjdbsd"
#Numberarray[5]="pstj"
#Numberarray[6]="ggbzl"
#Numberarray[7]="dbysltd"
#Numberarray[8]="dxsw"

#Stringarray
Stringarray[0]="BCTRZD"
#Stringarray[1]="PMGX"
#Stringarray[2]="DXPD"
#Stringarray[3]="TMPD"

sql_first="set hive.cli.print.header=true; set hive.cli.print.row.to.vertical=true;set hive.cli.print.row.to.vertical.num=1;"
sql_temp=""
for var in ${Numberarray[@]}
do
   sql_temp=${sql_temp}${sql_n//temps/${var}}
done

for var in ${Stringarray[@]}
do
   sql_temp=${sql_temp}${sql_s//temps/${var}}
done
sql_execute=${sql_first}${sql_temp}

#piconv -f gb2312 -t UTF-8 ./TTTTTTTT/XJFDDY1.txt > ./TTTTTTTT/XJFDDY2.txt
#sudo -S $HIVE_PA/bin/hive -e "$sql" <<EOF
#$PassWd
#EOF

echo $sql_execute
nohup $HIVE_PA/bin/hive -e "$sql_execute" > /home/hadoop/Output/HLX_Output/result_$1.txt 2>/home/hadoop/log/HLX_Execute_$1.log && touch /home/hadoop/Output/HLX_Output/end_$1 &
#$PassWd
#EOF
#echo "create table finished"

#$HOME/HLXFX_shell/Output.sh

#echo "EOF1"

